
package com.cptravel.activity.explore;

import java.util.ArrayList;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.core.api.ApiListenrDefaultImpl;
import com.core.api.B5MBaseResponse;
import com.core.controller.B5MBaseActivity;
import com.core.util.B5MActivityHelper;
import com.core.widget.pulltorefresh.PullToRefreshListView;
import com.cptravel.R;
import com.cptravel.activity.hot.HotDetailActivity;
import com.cptravel.adapter.HotAdapter;
import com.cptravel.api.GetListRequest;
import com.cptravel.api.GetListResponse;
import com.cptravel.bean.Class;
import com.cptravel.bean.Product;

public class ExploreItemActivity extends B5MBaseActivity
{
    private HotAdapter hotAdapter;
    private PullToRefreshListView mPullToRefreshListView;
    private GetListRequest mGetListRequest;
    private Class class1;

    @Override
    public int doGetContentViewId()
    {
        // TODO Auto-generated method stub
        return R.layout.exploreitem;
    }

    @Override
    public void doInitSubViews(View containerView)
    {
        // TODO Auto-generated method stub
        mPullToRefreshListView = (PullToRefreshListView) containerView.findViewById(R.id.pull_refresh_list);
        mPullToRefreshListView.setOnItemClickListener(new OnItemClickListener()
        {
            @Override
            public void onItemClick(AdapterView<?> arg0 , View arg1 , int arg2 , long arg3)
            {
                // TODO Auto-generated method stub
                Product product = hotAdapter.getList().get((int) arg3);
                Bundle bundle = new Bundle();
                bundle.putSerializable("product", product);
                B5MActivityHelper.startActivity(mActivity, HotDetailActivity.class, bundle);
            }
        });
    }

    @Override
    public void doInitDataes()
    {
        // TODO Auto-generated method stub
        class1 = (Class) getIntent().getSerializableExtra("class1");
        hotAdapter = new HotAdapter(mActivity, new ArrayList<Product>());
        mPullToRefreshListView.setAdapter(hotAdapter);
        mGetListRequest = new GetListRequest(new ApiListenrDefaultImpl()
        {
            @Override
            public void onSuccess(B5MBaseResponse b5mBaseResponse)
            {
                // TODO Auto-generated method stub
                super.onSuccess(b5mBaseResponse);
                GetListResponse getListResponse = (GetListResponse) b5mBaseResponse;
                hotAdapter.setList(getListResponse.products);
                hotAdapter.notifyDataSetChanged();
            }
        }, mProgressBar);
    }

    @Override
    public void doAfter()
    {
        // TODO Auto-generated method stub
        tv_title.setText(class1.title);
        if (!TextUtils.isEmpty(class1.classid))
        {
            mGetListRequest.classid = class1.classid;
            hotAdapter.getList().clear();
            mGetListRequest.start();
        }
    }

    @Override
    protected String getHeadTitle()
    {
        // TODO Auto-generated method stub
        return null;
    }
}
